package stdio.costa.imoca.api;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import stdio.costa.imoca.model.Address;

@Path("/address")
@Component
@Scope("request")
public class AddressApi {
	@PersistenceContext
	private EntityManager entityManager;

	@POST
	@Produces({ "application/json", "application/xml" })
	@Transactional
	public Address update(@FormParam("uuid") String uuid, @FormParam("whom") String whom, @FormParam("postcode") String postcode, @FormParam("province") String province,
			@FormParam("city") String city, @FormParam("district") String district, @FormParam("detail") String detail) {
		Address address = entityManager.find(Address.class, uuid);
		address.setWhom(whom);
		address.setPostcode(postcode);
		address.setProvince(province);
		address.setCity(city);
		address.setDistrict(district);
		address.setDetail(detail);
		return entityManager.merge(address);
	}
}
